package com.xxg.renrensearch.dao;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 分类与商品映射Dao
 *
 * @author xuxiaogang
 * @date 2021-11-26
 */
@Mapper
@Component
public interface RenrenShopGoodsCategoryMapDao {
    /**
     * 在商品ID范围内查询商品分类映射
     *
     * @param start 商品开始ID
     * @param end   商品结束ID
     * @return 结果
     */
    @Select("select goods_id as goodsId,category_id as categoryId from renren_shop_goods_category_map where goods_id between #{start} and #{end}")
    List<RenrenShopGoodsCategoryMap> selectByGoodIdRange(@Param("start") int start, @Param("end") int end);

    /**
     * 在商品ID范围内查询商品分类映射
     *
     * @param ids ID列表
     * @return 结果
     */
    @Select({"<script>",
            "select goods_id as goodsId,category_id as categoryId",
            "from renren_shop_goods_category_map where goods_id in",
            "<foreach collection='ids' item='id' open='(' separator=',' close=')'>",
            "#{id}",
            "</foreach>",
            "</script>"})
    List<RenrenShopGoodsCategoryMap> selectByGoodIds(@Param("ids") List<Integer> ids);

    /**
     * 根据商品ID列表删除记录
     *
     * @param ids ID列表
     */
    @Delete({"<script>",
            "delete from renren_shop_goods_category_map where goods_id in ",
            "<foreach collection='ids' item='id' open='(' separator=',' close=')'>",
            "#{id}",
            "</foreach>",
            "</script>"})
    void deleteByIds(@Param("ids") List<Integer> ids);
}